/**
 * File: StoredMatchMaqLoadProcessor.java
 * Created by: mhaimel
 * Created on: 19 Aug 2009
 * CVS:  $Id: StoredMatchMaqLoadProcessor.java,v 1.2 2009/12/07 09:49:17 mhaimel Exp $
 */
package uk.ac.ebi.curtain.processor.load.impl;

import java.io.File;

import uk.ac.ebi.curtain.controller.loader.impl.ConcurrentMatchHandler;
import uk.ac.ebi.curtain.processor.AbstractProcessor;
import uk.ac.ebi.curtain.processor.writer.BucketCollectionBean;
import uk.ac.ebi.curtain.util.io.MapEntryBean;
import uk.ac.ebi.curtain.util.io.MapEntryReader;
import uk.ac.ebi.curtain.utils.file.maq.MaqFlag;

/**
 * @author mhaimel
 *
 */
public class StoredMatchMaqLoadProcessor extends AbstractProcessor<BucketCollectionBean, BucketCollectionBean> {
	
	private ConcurrentMatchHandler matchHandler;
	private File dataMapFile;
	
	public void setMatchHandler(ConcurrentMatchHandler matchHandler) {
		this.matchHandler = matchHandler;
	}
	
	private ConcurrentMatchHandler getMatchHandler() {
		return matchHandler;
	}
	
	@Override
	protected BucketCollectionBean buildReturnObject() {
		return new BucketCollectionBean(null);
	}
	
	@Override
	public void process() {
		File file = getDataMapFile();
		MapEntryReader reader = new MapEntryReader(file);
		long cnt = 0;
		long mCnt = 0;
		for(MapEntryBean entry : reader){
			++cnt;
			if(getMatchHandler().addMatch(entry.getContigId(), entry.getReadId())){
				++mCnt;
			}
			if(cnt%1000000 == 0){
				getLog().debug("Checkpoint " + cnt + " with " + mCnt + " used for " + file + " ...");
			}
		}
		getLog().debug("Finished parsing " + cnt + " with " + mCnt + " used from " + file + "!");
	}

	public void setDataMapFile(File dataMapFile) {
		this.dataMapFile = dataMapFile;
	}

	public File getDataMapFile() {
		return dataMapFile;
	}
}
